<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 只能向右比较
        var arr = [7, 1, 5, 3, 6, 4]

        function guPiao(arr) {
            var max_out = 0;
            var min_in = arr[0]
            for (var i = 1; i < arr.length; i++) {
                if (arr[i] < min_in) {
                    min_in = arr[i]
                }
                if (arr[i] - min_in > max_out) {
                    max_out = arr[i] - min_in
                }
            }
            return max_out
        }

        console.log(guPiao(arr));

    </script>
</head>

<body>

</body>

</html>